package com.lb.pdm.controller;

import com.lb.pdm.common.result.GraceJSONResult;
import com.lb.pdm.entity.CertificateApplication;
import com.lb.pdm.entity.CertificateInfo;
import com.lb.pdm.entity.bo.CertificateApplicationApproval;
import com.lb.pdm.entity.bo.CertificateApplicationBO;
import com.lb.pdm.entity.bo.CertificateApplicationQuery;
import com.lb.pdm.entity.vo.CertificateApplicationVO;
import com.lb.pdm.service.CertificateApplicationService;
import com.lb.pdm.service.CertificateInfoService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Title: CertificateController
 * @Author Wood
 * @Package com.lb.pdm.controller
 * @Date 2025/10/29 16:39
 * @description:
 */
@RestController
@RequestMapping("/certificate")
@Tag(name = "证件管理", description = "证件办理相关接口")
public class CertificateController {
    @Autowired
    private CertificateApplicationService certificateApplicationService;
    @Autowired
    private CertificateInfoService certificateInfoService;

    @PostMapping("/apply")
    @Operation(summary = "申请证件")
    public GraceJSONResult apply(@RequestBody CertificateApplicationBO certificateApplicationBO, @RequestHeader("token") String token) {
        return certificateApplicationService.apply(certificateApplicationBO, token);
    }

    @GetMapping("/query")
    @Operation(summary = "查询证件申请信息")
    public GraceJSONResult query(@RequestParam(value = "idCard", required = false) String idCard,
                                 @RequestParam("certificateType") String certificateType,
                                 @RequestParam(value = "applicationType",required = false) Byte applicationType,
                                 @RequestParam(value = "applicationStatus", required = false) Byte applicationStatus,
                                 @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
                                 @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize) {
        CertificateApplicationQuery certificateApplicationQuery = new CertificateApplicationQuery(idCard, certificateType, applicationType, applicationStatus,pageNum,pageSize);
        List<CertificateApplicationVO> query = certificateApplicationService.query(certificateApplicationQuery);
        return GraceJSONResult.ok(query);
    }

    @PutMapping("/approval")
    @Operation(summary = "证件申请审批")
    public GraceJSONResult approval(@RequestBody CertificateApplicationApproval certificateApplicationApproval, @RequestHeader("token") String token) {
        return certificateApplicationService.approval(certificateApplicationApproval, token);
    }

    @PostMapping("/cancellation")
    @Operation(summary = "证件注销")
    public GraceJSONResult cancellation(@RequestParam("certificateNumber") String certificateNumber, @RequestHeader("token") String token) {
        return certificateInfoService.cancellation(certificateNumber, token);
    }
}
